/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Author:
 *     coolair.loveU2@gmail.com
 *******************************************************************************/

package org.skyfree.ghyll.tcard.core.internal;

import java.util.Date;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.skyfree.ghyll.tcard.core.IStoragePath;
import org.skyfree.ghyll.tcard.core.ITProjectDescription;
import org.skyfree.ghyll.tcard.core.TCardCore;

/**
 * This class ...
 */

public class TProjectDescription extends AbstractTResource implements ITProjectDescription
{
	public TProjectDescription(IStoragePath path)
	{
		super(path);
	}

	String name;
	private String comment;
	private String contractID;
	private Date createDate;
	private String status;
	TProject project;
	
	@Override
	public String getComment()
	{
		return this.comment;
	}

	@Override
	public String getContractID()
	{
		return this.contractID;
	}

	@Override
	public Date getCreateDate()
	{
		return this.createDate;
	}

	@Override
	public String getName()
	{
		return this.name;
	}

	@Override
	public void setComment(String comment)
	{
		this.comment = comment;
		this.dirty  = true;
	}

	@Override
	public void setContractID(String contractID)
	{
		this.contractID = contractID;
		this.dirty  = true;
	}

	@Override
	public void load() throws CoreException
	{
		try
		{
			this.provider.load(this);
		} catch (Exception e)
		{
			this.log(e);
			throw new CoreException(new Status(IStatus.ERROR,TCardCore.PLUGIN_ID,e.getMessage()));
		}
		this.loaded = true;
		this.dirty = false;
	}

	@Override
	public void save() throws CoreException
	{
		if(!this.dirty)return;
		try
		{
			this.provider.save(this);
		} catch (Exception e)
		{
			this.log(e);
			throw new CoreException(new Status(IStatus.ERROR,TCardCore.PLUGIN_ID,e.getMessage()));
		}
		this.dirty = false;
	}

	@Override
	public void setStatus(String status)
	{
		this.status = status;
		this.dirty  = true;
	}

	@Override
	public String getStatus()
	{
		return this.status;
	}

	@Override
	public void reload() throws CoreException
	{
		this.load();
	}

	@Override
	public void setCreateDate(Date date)
	{
		if(this.createDate==null)
		{
			this.createDate = date;
			this.dirty  = true;
		}
		
	}

	@Override
	public void setName(String name)
	{
		this.name = name;
		this.dirty  = true;
		
	}
	
}
